package com.ruoyi.voucher.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.voucher.domain.VoucherWord;
import com.ruoyi.voucher.service.IVoucherWordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/**
 * 凭证字Controller
 * 
 * @author ruoyi
 * @date 2025-02-21
 */
@RestController
@RequestMapping("/voucherWord")
public class VoucherWordController extends BaseController
{
    @Autowired
    private IVoucherWordService voucherWordService;

    /**
     * 查询凭证字列表
     */
    @RequiresPermissions("voucher:voucherWord:list")
    @GetMapping("/list")
    public TableDataInfo list(VoucherWord voucherWord)
    {
        startPage();
        List<VoucherWord> list = voucherWordService.selectVoucherWordList(voucherWord);
        return getDataTable(list);
    }

    /**
     * 导出凭证字列表
     */
    @RequiresPermissions("voucher:voucherWord:export")
    @Log(title = "凭证字", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VoucherWord voucherWord)
    {
        List<VoucherWord> list = voucherWordService.selectVoucherWordList(voucherWord);
        ExcelUtil<VoucherWord> util = new ExcelUtil<VoucherWord>(VoucherWord.class);
        util.exportExcel(response, list, "凭证字数据");
    }

    /**
     * 获取凭证字详细信息
     */
    @RequiresPermissions("voucher:voucherWord:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(voucherWordService.selectVoucherWordById(id));
    }

    /**
     * 新增凭证字
     */
    @RequiresPermissions("voucher:voucherWord:add")
    @Log(title = "凭证字", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody @Valid VoucherWord voucherWord)
    {
        return toAjax(voucherWordService.insertVoucherWord(voucherWord));
    }

    /**
     * 修改凭证字
     */
    @RequiresPermissions("voucher:voucherWord:edit")
    @Log(title = "凭证字", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody @Valid VoucherWord voucherWord)
    {
        return toAjax(voucherWordService.updateVoucherWord(voucherWord));
    }

    /**
     * 删除凭证字
     */
    @RequiresPermissions("voucher:voucherWord:remove")
    @Log(title = "凭证字", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) throws Exception {
        return toAjax(voucherWordService.deleteVoucherWordByIds(ids));
    }
}
